<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>任务管理</title>
    <script type="text/javascript">
      var newWorkWin;
      var editWorkWin;
      var workId;
      Ext.onReady(function(){
        //列车管理---------------------------------------------------------
        //生成有关列车的Grid
        var workDS = new Ext.data.Store({
          paramNames: {
            start: "start",
            limit: "limit"
          },
          baseParams: {
            start: 0,
            limit: pageSize
          },
          proxy: new Ext.data.HttpProxy({
            url: '/work/getWorks'
          }),
          reader:new Ext.data.JsonReader({
            totalProperty: 'total',
            root:'work'
          },[
            {name:'id'},
            {name:'name'}
          ]
        )
        });

        var workSM = new Ext.grid.CheckboxSelectionModel();
        var workCM = new Ext.grid.ColumnModel([
          new Ext.grid.RowNumberer({width: 30}),
          workSM,
          {header:'任务',sortable:true,dataIndex:'name',width:300}
        ]);

        var workGrid =  new Ext.grid.GridPanel({
          ds: workDS,
          cm: workCM,
          sm: workSM,
          width: screenWidth-240,
          height: screenHeight-310,
          iconCls: 'icon-grid',
          bbar: new Ext.PagingToolbar({
            pageSize: pageSize,
            store: workDS,
            displayInfo: true,
            displayMsg: "显示第 {0} 条到 {1} 条记录，一共 {2} 条",
            emptyMsg: "没有记录"
          }),
          tbar: ['-',{
              text: '添加养护任务',
              width:50,
              iconCls: 'addItem',
              handler : function(){
                newWorkWin = new Ext.Window({
                  layout: 'fit',
                  width:267,
                  height:145,
                  closeAction: 'destroy',
                  plain: true,
                  modal: true,
                  conswork:true,
                  //modal: true,
                  title: '添加养护任务',
                  autoLoad: {
                    url: "/work/newWork",
                    scripts: true
                  }
                });
                newWorkWin.on("destroy",function(){
                  workDS.reload();
                });
                newWorkWin.resizable = false;
                newWorkWin.show();
              }
            },{
              text: '编辑养护任务',
              width:50,
              iconCls: 'editItem',
              handler : function(){
                var records = workGrid.getSelectionModel().getSelections();
                if(records.length==0){
                  Ext.MessageBox.alert('提示信息', '请先选中一条记录后，再编辑。');
                }else{
                  //把表单添加到窗口中
                  workId = records[0].get('id');
                  editWorkWin = new Ext.Window({
                    title: '编辑养护任务',
                    layout:'fit',
                    width:267,
                    height:145,
                    closeAction:'destroy',
                    conswork:true,
                    plain: true,
                    modal: true,
                    autoLoad: {
                      url: "/work/editWork?id=" + workId,
                      scripts: true
                    }
                  });
                  editWorkWin.on("destroy",function(){
                    workDS.reload();
                  });
                  editWorkWin.resizable = false;
                  editWorkWin.show();
                }

              }
            }
          ]
        });
        workGrid.render('workList');
        workDS.load();
      })
    </script>
  </head>
  <body>
    <div id="workList"></div>
  </body>
</html>
